define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'packages/index' + location.search,
                    add_url: 'packages/add',
                    edit_url: 'packages/edit',
                    del_url: 'packages/del',
                    multi_url: 'packages/multi',
                    import_url: 'packages/import',
                    shezhi_url:'packages/shezhi',
                    dragsort_url: 'ajax/weigh',
                    table: 'packages',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                // fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: '代理设置',
                                    text: '代理设置',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'packages/shezhi'
                                }
                            ],
                        },
                        {field: 'id', title: __('Id')},
                        {field: 'packages_id', title: __('Packages_id')},
                        {field: 'type', title: __('展现类型'), searchList: {"1":__('互通'),"2":__('代理端'),"3":__('用户端')}, formatter: Table.api.formatter.status},
                        {field: 'platform_type', title: __('Platform_type'), searchList: {"1":__('Platform_type 1'),"2":__('Platform_type 2'),"3":__('Platform_type 3'),"4":__('Platform_type 4'),"5":__('Platform_type 5'),"6":__('Platform_type 6'),"7":__('Platform_type 7'),"8":__('Platform_type 8'),"9":__('Platform_type 9'),"10":__('Platform_type 10')}, formatter: Table.api.formatter.status},
                        {field: 'day', title: __('Day'), searchList: {"1":__('Day 1'),"2":__('Day 2'),"3":__('Day 3'),"4":__('Day 4'),"5":__('Day 5'),"6":__('Day 6'),"7":__('Day 7')}, formatter: Table.api.formatter.status},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'supplier', title: __('供应商'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'user_name', title: __('User_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'card_type', title: __('Card_type'), searchList: {"1":__('Card_type 1'),"2":__('Card_type 2'),"3":__('Card_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_channel', title: __('Pay_channel'), searchList: {"1":__('Pay_channel 1'),"2":__('Pay_channel 2')}, formatter: Table.api.formatter.normal},
                        {field: 'cate_id', title: __('Cate_id'), searchList: {"1":__('Cate_id 1'),"2":__('Cate_id 2'),"3":__('Cate_id 3'),"4":__('Cate_id 4'),"5":__('Cate_id 5'),"6":__('Cate_id 6')}, formatter: Table.api.formatter.normal},
                        {field: 'jiesuan_type', title: __('Jiesuan_type'), searchList: {"1":__('Jiesuan_type 1'),"2":__('Jiesuan_type 2')}, formatter: Table.api.formatter.status},

                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'photos', title: __('Photos'),events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'rebate', title: __('Rebate'), operate:'BETWEEN'},
                        // {field: 'h5url', title: __('H5url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'is_extend', title: __('Is_extend'), searchList: {"1":__('Is_extend 1'),"2":__('Is_extend 2')}, formatter: Table.api.formatter.status},
                        {field: 'monthly', title: __('Monthly'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'flow', title: __('Flow'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'call_minutes', title: __('Call_minutes'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'pact', title: __('Pact'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'age', title: __('Age'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'demand', title: __('Demand'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},


                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        shezhi: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
